package com.leetcode;

/**
 * 服务启动时间
 *
 * @author fy
 * @date 2023/3/10 10:52
 */
public class Solution {


    public static void main(String[] args) {
        int n = 3;
        int[][] t = new int[n][n];
//        for (int i = 0; i < n; i++) {
//            for (int j = 0; j < n; j++) {
//                if (i == j) {
//                    t[i][j] = 5;
//                } else {
//                    t[i][j] = 0;
//                }
//            }
//        }
        t[0][0] = 5;
        t[2][2] = 3;
        t[1][1] = 2;
        t[2][0] = 1;
        t[2][1] = 1;

        print(t, 3);

        System.out.println(getInitTime(2, t, 3));
    }

    public static void print(int[][] t, int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(t[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static int getInitTime(int i, int[][] t, int n) {
        int max = 0;
        for (int k = 0; k < n; k++) {
            if (i != k && t[i][k] != 0) {
                max = Math.max(max, getInitTime(k, t, n));
            }
        }
        return t[i][i] + max;
    }

}
